	

<script type="text/javascript" src="<?php echo URL_JS; ?>ckeditor/ckeditor.js"></script>


<?php
// Si le fichier de qui dÔøΩfinie les constantes n'a pas encore ÔøΩtÔøΩ appelÔøΩ on le charge
if (!defined('CONFIGURATION_FILE_LOADED'))
    include( 'includes/configuration_include.php');


include( PATH_VIEWS . 'create_new_view.php');
include( PATH_MODELS . 'create_new_model.php');

$bdd = model_db_connexion();
$req = select_last_id($bdd);
// Si l'utilisateur est deja logue
if (!empty($_SESSION['id_user'])) {


    if (isset($_POST['description'])) {


        $last_id = count_new($bdd);

        
        if ($last_id != 0) {
while($donnees = $req->fetch(PDO::FETCH_ASSOC))
{$last_id = $donnees['id_new'];}

                        $i = 0;
                                $last_id++;
                         if (!empty($_POST['description']) && !empty($_POST['title']) && !empty($_POST['heure'])) {
      

        $description = $_POST["description"];
        $title = $_POST["title"];
        $heure =  $_POST["heure"];
                        if (isset($_FILES['photo']) AND $_FILES['photo']['error'] == 0) {
                            if (upload_photo_test() != 3) {
                                $type_img = upload_photo_test();
                                upload_photo($last_id);
        model_create_news($bdd, $description, $title,$type_img,$heure);
                                $i++;
                            } else {
                                echo' Votre image/video n\'est pas au bon format';
                                $i++;
                            }
                        }else{
                            
                                    model_create_news($bdd, $description, $title,3,$heure);

                        }}else{echo 'Veuillez remplir l\'ensemble des champs';}
                    }else {
                    $last_id = 0;
                    $i = 0;
                    
  if (!empty($_POST['description']) AND !empty($_POST['title'])) {
       $description = $_POST["description"];
        $title = $_POST["title"];
                $heure =  $_POST["heure"];

      if (isset($_FILES['photo']) AND $_FILES['photo']['error'] == 0) {
                        if (upload_photo_test() != 3) {

                            $type_img = upload_photo_test();


                            model_create_news($bdd, $description, $title,$type_img,$heure);
$dd = $bdd->lastInsertId();
upload_photo($dd);
        viewCreated();

                            $i++;
                        } else {
                            echo' Votre image/video n\'est pas au bon format';
                            $i++;
                        }
                    } else {
                        "                       Vous devez mettre une photo!
";
                    }}else{echo 'Veuillez remplir l\'ensemble des champs';;}}
        
        
        
        
        
        

        createNews();
    } else {
        createNews();
    }
} else {
    echo '<span class="template_span">' . LANG_NO_CONNECT . '</span>'; }
  function upload_photo($count_news) {
    if (isset($_FILES['photo'])) {
        if ($_FILES['photo']['error'] == 0) {

            if ($_FILES['photo']['size'] <= 7000000) {

                $infosfichier = pathinfo($_FILES['photo']['name']);

                $extension_upload = $infosfichier['extension'];
  $extension_upload =strtolower($extension_upload);
            $extensions_autorisees = array('webm', 'jpeg');

                if (in_array($extension_upload, $extensions_autorisees)) {




                    //$name= $id_work .".". $extension_upload;

                    move_uploaded_file($_FILES['photo']['tmp_name'], "design/img/news/" . $count_news . "." . $extension_upload . "");
                    return TRUE;
                } else {
                    echo '<span class="template_span">Votre format de l\'image 1 n\'est pas accepte, veuillez reessayer</span><br />';
                    return FALSE;
                }
            }
        } else {
            return FALSE;
        }
    }
}

function upload_photo_test() {
    if (isset($_FILES['photo'])
            && $_FILES['photo']['error'] == 0) {

        if ($_FILES['photo']['size'] <= 7000000) {

            $infosfichier = pathinfo($_FILES['photo']['name']);

            $extension_upload = $infosfichier['extension'];
  $extension_upload =strtolower($extension_upload);

            $extensions_autorisees = array('webm', 'jpeg');

            if (in_array($extension_upload, $extensions_autorisees)) {




                switch ($extension_upload) {
                    case 'webm' :
                        return 0;
                        break;
                    case 'jpeg' :
                        return 1;
                        break;
                                  }
                //$name= $id_work .".". $extension_upload;
            } else {
                return 3;
            }
        }
    } else {
        return FALSE;
    }}

    echo'<script type="text/javascript">
       CKEDITOR.replace("visu", 
    {
    height:"100", width:"500"
    });

    </script>';


?>
